#include <iostream>
#include <memory>
// 1

class Test
{
public:
    Test()
    {
        std::cout << "构造函数\n";
    }
    ~Test()
    {
        std::cout << "析构函数\n";
    }
    void show()
    {
        std::cout << "herlloword" << std::endl;
    }
};

template <typename T>
class SmartPoint
{
public:
    SmartPoint(T *p) : p(p)
    {
        count++;
    };
    ~SmartPoint()
    {
        count--;
        if (count == 0)
            delete p;
    }
private:
    T *p;
    static int count; // 计数，每多一个指针，加1  实际应该一个指针配一个count
};

int main()
{
    std::shared_ptr<Test> p = std::make_shared<Test>();
    p->show(); // 也重载了指针运算符
    std::shared_ptr<Test> p2 = p;
    p2->show();
    std::shared_ptr<Test> p3;
    p3 = p;
    p3->show();
    return 0;
}
